﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using MvcDataTables;

namespace MvcDataTablesDemo.Models
{
    public class DirectoryModel
    {
        private readonly DirectoryInfo _directoryInfo;

        public DirectoryModel() {}

        public DirectoryModel(DirectoryInfo directoryInfo)
        {
            _directoryInfo = directoryInfo;
            Name = _directoryInfo.Name;
            FullName = _directoryInfo.FullName;
        }

        [EditableColumn]
        public string Name { get; set; }
        public string FullName { get; set; }
        public DateTime CreateDateTime { get { return _directoryInfo != null ? _directoryInfo.CreationTime : DateTime.MinValue; } }
        public IEnumerable<FileModel> ExecutableFiles { get { return _directoryInfo != null ? _directoryInfo.GetFiles("*.exe").Select(lmb => new FileModel(lmb)) : null; } }
        public IEnumerable<FileInfo> OtherFiles { get { return _directoryInfo != null ? _directoryInfo.GetFiles().Where(lmb => lmb.Extension != ".exe") : null; } }
    }
}